<?php
require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';

class CategoryDao extends BaseDao{

   protected $_name;

    public function  _setup() {
        $this->_name = $this->prefix() . "categories";
        parent::_setup();
    }

    public function getCategories(){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where('is_delete = 0');
        $select->order('sort_order');
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
    }

    public function getCategoryByParentId($parentId){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where('parent_id = ?', $parentId);
        $select->where('is_delete = 0');
        $select->order('sort_order');
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
    }

    public function updateCategory($id,$category){
			$where = $this->db_w->quoteInto('id = ?', $id);
			$this->update($category,$where);
    }
}